<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
   "http://www.w3.org/TR/html4/strict.dtd">
   
<html xmlns:wicket="http://wicket.apache.org/dtds.data/wicket-xhtml1.4-strict.dtd" lang="fr">
	<wicket:head>
		<title>Navigation à travers les services</title>
		<wicket:link>
			<script type="text/javascript" wicket:id="browseUrlScript"></script>
			<script type="text/javascript">
				var first = false;
				
				function callWicket(id) {
					var wcall = wicketAjaxGet(getViewServiceUrl() + '&id=' + id, 
							/**/function() { }, /**/function() { });
				};
				
				$(function () {
					$("#treeview").jstree({ 
						plugins : [ "themes", "cookies", "json_data", "ui", "contextmenu" ],
						themes : {
							theme: "classic"
						},
						json_data: {
							progressive_render: true,
							data: [
							         {
		                    			data : "Ministère",
		                    			attr : {
		                    				id : "0"
		                    			},
		                    			state : "closed"
		                			}
							],
							ajax : {
								async: true,
								url: function(n) {
									return getBrowseUrl();
								},
								datatype: "json",
								data: function (n) {
									return { id : n.attr ? n.attr("id") : 0 };
								}
							}
						},
						contextmenu : {
							items : function(obj) {
								var menu = {};
								var nodeId = obj.attr('id');
								var nodeRel = obj.attr('rel');
								if (nodeId != '0' && nodeRel != 'disabled') {
									menu = {
										"ccp" : false,
										"rename" : false,
										"edit" : {
											label : "Editer",
											icon : "styles/plugins/buttons/icons/edit.png",
											action : function (obj) { 
													var nodeId = obj.attr('id');
													document.location.href = obj.attr('editUrl');
													return true;
												},
											_disabled : false,
											separator_after : true
										},
										"create" : {
											label : "Créer",
											icon : "styles/plugins/buttons/icons/add.png",
											action : function (obj) {
													var nodeId = obj.attr('id');
													document.location.href = obj.attr('createUrl');
													return true;
												},
											_disabled : false,
											separator_after : true
										},
										"remove" : {
											label : "Supprimer",
											icon : "styles/plugins/buttons/icons/delete.png",
											action : function (obj) { 
													var nodeId = obj.attr('id');
													document.location.href = obj.attr('deleteUrl');
													return true;
												},
											_disabled : false
										}
									}
								}
								
								return menu;
							}
						},
						core : {
							html_titles : true,
							strings : {
								loading : "Chargement en cours..."
							}
						}
					});

					$("#treeview").bind("select_node.jstree", function(e,data) {
						var href = data.rslt.obj.attr("href");
				        var path = window.location.href;
				        id = data.rslt.obj.attr("id");

				        return callWicket(id);
						/*
						var href = data.rslt.obj.attr("href");
				        var path = window.location.href;
				        id = data.rslt.obj.attr("id");
				        document.location.href = path + "&id=" + id;
				        return true;
				        */
					});
					
				});
			</script>
		</wicket:link>
	</wicket:head>
<body>

<wicket:extend>
	<a href="javascript:void(0);" onclick="$('#treeview').jstree('refresh', -1);">Rafraîchir l'arbre</a>
	<div class="span-6" id="treeview-wrapper">
		<span id="treeview" wicket:id="treeview"></span>
	</div>

	 <div class="content span-18 last">
	 	<span wicket:id="viewServicePanel"></span>
	</div>
</wicket:extend>

</body>
</html>
